#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <iostream>

using namespace std;

const int MaxN = 6005;
int re[MaxN];

int main(){
	
	int n ;
	scanf("%d",&n);
	for(int i = 0 ; i < MaxN ; i ++)
		re[i] = 0;
	for(int i = 0 ; i < n; i ++){
		int temp;
		scanf("%d",&temp);
		re[temp] ++;
	}
	int ans = 0;
	for(int i = MaxN - 1 ; i >= 0 ; i --){
		if(re[i] <= 1)
			continue;
		while(re[i] > 1){
			for(int j = i + 1 ; j <= MaxN ; j ++){
				if(re[j] == 0){
					re[j] = 1;
					ans += (j - i);
					re[i] -- ;
					break;
				}
			}
		}
	}
	printf("%d\n", ans);
	
	return 0;
}